package com.example.demo.modules.test.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.util.ResultUtil;
import com.example.demo.common.util.entity.ListSub;
import com.example.demo.common.util.entity.PageFactory;
import com.example.demo.common.util.entity.Result;
import com.example.demo.common.util.entity.ResultEnum;
import com.example.demo.modules.test.dto.classes.ClassDTO;
import com.example.demo.modules.test.dto.classes.ClassQueryDTO;
import com.example.demo.modules.test.service.IClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lmy
 * @since 2022-12-28
 */
@RestController
@RequestMapping("/test/class")
@Api(tags = "测试模块")
public class ClassController {

    @Resource
    private IClassService iClassService;

    @ApiOperation(value = "班级列表", notes = "班级列表")
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public Result<ListSub<ClassDTO>> page(PageFactory pageFactory, ClassQueryDTO queryDTO){
        Page<ClassDTO> page = new Page<>(pageFactory.getStart(), pageFactory.getLength());
        IPage<ClassDTO> iPage = iClassService.listClass(page, queryDTO);
        return ResultUtil.success(iPage);
    }

    @ApiOperation(value = "导入班级", notes = "导入班级")
    @RequestMapping(value = "importClass", method = RequestMethod.POST)
    public Result importClass(String filePath){
        ResultEnum info = iClassService.importClass(filePath);
        return ResultUtil.info(info);
    }

    @ApiOperation(value = "导出班级", notes = "导出班级")
    @RequestMapping(value = "exportClass", method = RequestMethod.GET)
    public Result exportClass(ClassQueryDTO queryDTO){
        return iClassService.exportClass(queryDTO);
    }
}

